package per.turtle.common.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * topic交换机模型，需要一个topic交换机，两个队列和三个binding
 *
 * @author yuj
 */
@Configuration
public class TopicExchangeConfig {

    /**
     * 3个binding将交换机和相应队列连起来
     */
    @Bean
    public Binding bindingTopic1() {
        // “*”用来表示一个单词
        return BindingBuilder.bind(topicQueue1()).to(topicExchange()).with("*.orange.*");
    }

    @Bean
    public Binding bindingTopic2() {
        // “#”用来匹配多个单词
        return BindingBuilder.bind(topicQueue2()).to(topicExchange()).with("lazy.#");
    }

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("my_topic");
    }

    @Bean
    public Queue topicQueue1() {
        return new Queue("topic_queue1");
    }

    @Bean
    public Queue topicQueue2() {
        return new Queue("topic_queue2");
    }

}
